<template>
    <div>
        <div class="e-form" v-if="dialogVisible === false">
            <BillTop :title="$route.meta.title" @cancel="handleClose"></BillTop>
            <div class="tabs warningTabs"></div>
            <div class="tabs" v-if="Object.keys(formData).length != 0">
                <el-tabs
                    tab-position="left"
                    v-model="tabsName"
                    @tab-click="onChangeTab"
                    v-if="auditState.canModify"
                >
                    <!-- 基本信息 -->
                    <el-tab-pane
                        label="基本信息"
                        name="baseInfo"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="包件信息"
                        name="detail"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="采购清单"
                        name="tenderList"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="补遗澄清"
                        name="clarification"
                        :disabled="clickTabFlag"
                        v-if="formData.count !== 0"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="采购条款"
                        name="clause"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="附件信息"
                        name="attach"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="审核历史"
                        name="auditHistory"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <div>
                        <div id="baseInfoCon" class="con">
                            <div class="tabs-title" id="baseInfo">基本信息</div>
                            <div style="width: 100%" class="form">
                                <el-form
                                    :model="formData"
                                    label-width="170px"
                                    :rules="rules"
                                    ref="ruleForm"
                                >
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="补遗编号"
                                                width="230"
                                                prop="billNo"
                                            >
                                                <span>{{ formData.billNo }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="补遗日期"
                                                width="200"
                                                prop="tenderName"
                                            >
                                                <el-date-picker
                                                    v-model="formData.changeDate"
                                                    type="date"
                                                    placeholder="选择日期"
                                                    :clearable="false"
                                                    value-format="yyyy-MM-dd"
                                                >
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="租赁编号"
                                                width="230"
                                                prop="billNo"
                                            >
                                                <el-input v-model="tenderId" disabled></el-input>
                                                <ComShowBiddingButton
                                                    :tenderId="tenderId"
                                                    mod="equipHire"
                                                />
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="拟招标项目名称"
                                                width="200"
                                                prop="tenderName"
                                            >
                                                <el-input v-model="formData.tenderName"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="租赁人"
                                                width="230"
                                                prop="tenderUser"
                                            >
                                                <ComInputSelectUnit
                                                    :orgName.sync="formData.tenderUser"
                                                    :orgId.sync="formData.tenderUserId"
                                                    :SelectedIDs="
                                                        formData.tenderUserId !== ''
                                                            ? [formData.tenderUserId]
                                                            : []
                                                    "
                                                    type="getParentOrg"
                                                />
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="招标方式" prop="tenderForm">
                                                <el-select
                                                    v-model="formData.tenderForm"
                                                    placeholder="请选择"
                                                    @change="selectChange($event, '招标方式')"
                                                >
                                                    <el-option
                                                        v-for="item in options.tenderForm"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value"
                                                    >
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="申请日期" prop="applyTime">
                                                <el-date-picker
                                                    v-model="formData.applyTime"
                                                    type="date"
                                                    placeholder="选择日期"
                                                    :clearable="false"
                                                >
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <!-- 需要id和name -->
                                            <el-form-item
                                                label="申请单位"
                                                width="230"
                                                prop="applyOrgName"
                                            >
                                                <ComInputSelectUnit
                                                    :orgName.sync="formData.applyOrgName"
                                                    :orgId.sync="formData.applyOrgId"
                                                    :SelectedIDs="
                                                        formData.applyOrgId !== ''
                                                            ? [formData.applyOrgId]
                                                            : []
                                                    "
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="拟租赁金额（元）"
                                                width="200"
                                                prop="tenderAmount"
                                            >
                                                <span>{{ formData.tenderAmount }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="投标保证金（元）"
                                                prop="tenderBail"
                                            >
                                                <el-input
                                                    v-model="formData.tenderBail"
                                                    v-enterJustFloat
                                                    @blur="inputblur(formData, 'tenderBail')"
                                                ></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="租赁公告"
                                                prop="tenderNotice"
                                                v-if="
                                                    formData.tenderForm !== '2' &&
                                                    formData.tenderForm !== '4'
                                                "
                                            >
                                                <el-button
                                                    style="width: 222px"
                                                    class="btn-greenYellow"
                                                    @click="handleNotice"
                                                    >招标公告</el-button
                                                >
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="录入机构" prop="orgName">
                                                <span>{{ formData.orgName }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="状态">
                                                <span v-if="formData.releaseState === 1">
                                                    已发布
                                                </span>
                                                <span v-else>{{
                                                    formData.state | state(this)
                                                }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="租赁类型" prop="leaseType">
                                                <el-select
                                                    v-model="formData.leaseType"
                                                    placeholder="请选择"
                                                >
                                                    <el-option
                                                        v-for="(item, index) in options.leaseType"
                                                        :key="index + 1"
                                                        :label="item"
                                                        :value="index + 1"
                                                    >
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <ComNullify :formData="formData" />
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="币种" prop="currencyId">
                                                <el-select
                                                    v-model="formData.currencyId"
                                                    placeholder="请选择"
                                                    @change="selectChange($event, '币种')"
                                                >
                                                    <el-option
                                                        v-for="item in options.currency"
                                                        :key="item.kvValue"
                                                        :label="item.kvKey"
                                                        :value="item.kvValue"
                                                    >
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-form-item
                                            label="租赁需求陈述"
                                            prop="purchaseDemandStatement"
                                        >
                                            <el-input
                                                type="textarea"
                                                :rows="2"
                                                placeholder="请输入内容"
                                                v-model="formData.purchaseDemandStatement"
                                                style="margin-right: 110px"
                                            >
                                            </el-input>
                                        </el-form-item>
                                    </el-row>
                                    <el-row>
                                        <el-form-item label="变更原因" prop="changeReason">
                                            <el-input
                                                type="textarea"
                                                :rows="2"
                                                placeholder="请输入内容"
                                                v-model="formData.changeReason"
                                                style="margin-right: 110px"
                                            >
                                            </el-input>
                                        </el-form-item>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="本位币" prop="baseCurName">
                                                <!-- 传id和名称 -->
                                                <span>{{ formData.baseCurName }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col
                                            :span="12"
                                            v-if="formData.baseCurName !== formData.currency"
                                        >
                                            <el-form-item label="人民币汇率" prop="rmbRate">
                                                <span>{{ formData.rmbRate }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12" v-if="formData.releaseState === 1">
                                            <el-form-item label="发布时间：">
                                                <!-- 传id和名称 -->
                                                <span>{{ formData.relaseTime }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </div>
                        </div>

                        <div id="detailCon" class="con">
                            <div class="tabs-title" id="detail">包件信息</div>
                            <div>
                                <ComDetailsOfProposedIndex
                                    ref="ComDetailsOfProposedIndex"
                                    :tenderData="formData"
                                    v-model="detailsData"
                                    @onChangeTab="onChangeTab"
                                    :tenderListData="tenderListData"
                                    :auditState="auditState"
                                />
                            </div>
                        </div>

                        <div id="tenderListCon" class="con">
                            <div class="tabs-title" id="tenderList">招标清单</div>
                            <!-- :isAdd="auditState.canModify"
                                :isEdit="auditState.canModify" -->
                            <ComtenderListIndex
                                ref="ComtenderListIndex"
                                :auditState="auditState"
                                :state="formData.state"
                                :detailsData="detailsData"
                                v-model="tenderListData"
                                @onChangeTab="onChangeTab"
                            />
                        </div>

                        <div id="clarification" class="con" v-if="formData.count !== 0">
                            <div class="tabs-title" id="clause">
                                补遗澄清
                                <!-- <el-button @click="saveClar">测试保存</el-button> -->
                            </div>
                            <ComQuillEditor ref="ComQuillEditor" v-model="clauseParams.content" />
                        </div>

                        <div id="clauseCon" class="con">
                            <div class="tabs-title" id="clause">条款需求未定</div>
                            <!-- <div class="tabs-title" id="clause">通用合同条款</div>
                            <div class="e-table" style="min-height: auto">
                                <el-table
                                    :data="tableData"
                                    border
                                    style="width: 100%"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    :cell-class-name="cellClsNm"
                                >
                                    <el-table-column show-overflow-tooltip prop="a1" label="序号">
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="a"
                                        label="所属单位"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="b"
                                        label="通用合同条款编号"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="c"
                                        label="合同条款名称"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="d"
                                        label="条款明细查阅"
                                    >
                                    </el-table-column>
                                </el-table>
                                <ComPagination />
                            </div>

                            <div class="tabs-title" style="margin-top: 20px">项目专用合同条款</div>
                            <div class="e-table" style="min-height: auto; margin-bottom: 20px">
                                <div class="top">
                                    <div class="left">
                                        <div>
                                            <el-button size="small" class="btn-greenYellow"
                                                >新增</el-button
                                            >
                                            <el-button size="small" class="btn-greenYellow"
                                                >删除</el-button
                                            >
                                        </div>
                                    </div>
                                </div>
                                <el-table
                                    :data="tableData"
                                    border
                                    style="width: 100%"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    :cell-class-name="cellClsNm"
                                >
                                    <div class="top">
                                        <div class="left">
                                            <el-button size="mini">新增</el-button>
                                            <el-button size="mini">删除</el-button>
                                        </div>
                                    </div>
                                    <el-table-column show-overflow-tooltip prop="a1" label="序号">
                                    </el-table-column>
                                    <el-table-column show-overflow-tooltip prop="a" label="条目号">
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="b"
                                        label="原条款内容"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="c"
                                        label="专用合同条款内容"
                                    >
                                    </el-table-column>
                                </el-table>
                                <ComPagination />
                            </div> -->
                        </div>

                        <div id="attachCon" class="con">
                            <div class="tabs-title" id="attach">附件信息</div>
                            <ComAttachIndex
                                bucketName="tender"
                                :relationId="billId"
                                :isView="
                                    (auditState.canAudit === false &&
                                        auditState.canModify === false) ||
                                    Object.keys(auditState).length === 0
                                "
                                ref="ComAttachIndex"
                                :key="1"
                            />
                        </div>

                        <div id="auditHistoryCon" class="con">
                            <div class="tabs-title" id="auditHistory">审核历史</div>
                            <ComExaHistory billType="60291" ref="ComExaHistory" />
                        </div>
                    </div>
                </el-tabs>
                <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab" v-else>
                    <!-- 基本信息 -->
                    <el-tab-pane
                        label="基本信息"
                        name="baseInfo"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="包件信息"
                        name="detail"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="采购清单"
                        name="tenderList"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="补遗澄清"
                        name="clarification"
                        :disabled="clickTabFlag"
                        v-if="formData.count !== 0"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="采购条款"
                        name="clause"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="附件信息"
                        name="attach"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="审核历史"
                        name="auditHistory"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <div>
                        <div id="baseInfoCon" class="con">
                            <div class="tabs-title" id="baseInfo">基本信息</div>
                            <div style="width: 100%" class="form">
                                <el-form
                                    :model="formData"
                                    label-width="170px"
                                    :rules="rules"
                                    ref="ruleForm"
                                >
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="补遗编号" width="230">
                                                <span>{{ formData.billNo }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="补遗日期"
                                                width="200"
                                                prop="tenderName"
                                            >
                                                <span>{{ formData.changeDate }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="租赁编号"
                                                width="230"
                                                prop="billNo"
                                            >
                                                <el-input v-model="tenderId" disabled></el-input>
                                                <ComShowBiddingButton
                                                    :tenderId="tenderId"
                                                    mod="equipHire"
                                                />
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="拟招标项目名称"
                                                width="200"
                                                prop="tenderName"
                                            >
                                                <span>{{ formData.tenderName }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="租赁人"
                                                width="230"
                                                prop="tenderUser"
                                            >
                                                <ComInputSelectUnit
                                                    :orgName.sync="formData.tenderUser"
                                                    :orgId.sync="formData.tenderUserId"
                                                    :SelectedIDs="
                                                        formData.tenderUserId !== ''
                                                            ? [formData.tenderUserId]
                                                            : []
                                                    "
                                                    :edit="false"
                                                />
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="招标方式" prop="tenderForm">
                                                <span>{{
                                                    formData.tenderForm | tenderForm(this)
                                                }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="申请日期" prop="applyTime">
                                                <span>{{ formData.applyTime }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <!-- 需要id和name -->
                                            <el-form-item
                                                label="申请单位"
                                                width="230"
                                                prop="applyOrgName"
                                            >
                                                <ComInputSelectUnit
                                                    :orgName.sync="formData.applyOrgName"
                                                    :orgId.sync="formData.applyOrgId"
                                                    :SelectedIDs="
                                                        formData.applyOrgId !== ''
                                                            ? [formData.applyOrgId]
                                                            : []
                                                    "
                                                    :edit="false"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="拟租赁金额（元）"
                                                width="200"
                                                prop="tenderAmount"
                                            >
                                                <span>{{ formData.tenderAmount }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="投标保证金（元）"
                                                prop="tenderBail"
                                            >
                                                <span>{{ formData.tenderBail }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item
                                                label="租赁公告"
                                                prop="tenderNotice"
                                                v-if="
                                                    formData.tenderForm !== '2' &&
                                                    formData.tenderForm !== '4'
                                                "
                                            >
                                                <el-button
                                                    style="width: 222px"
                                                    class="btn-greenYellow"
                                                    @click="handleNotice"
                                                    >招标公告</el-button
                                                >
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="录入机构" prop="orgName">
                                                <span>{{ formData.orgName }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="状态">
                                                <span>{{ formData.state | state(this) }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="租赁类型">
                                                <span>{{
                                                    formData.leaseType | leaseType(this)
                                                }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <ComNullify :formData="formData" />
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="币种" prop="currencyId">
                                                <span>{{
                                                    formData.currencyId | currencyId(this)
                                                }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-form-item
                                            label="租赁需求陈述"
                                            prop="purchaseDemandStatement"
                                        >
                                            <span>{{ formData.purchaseDemandStatement }}</span>
                                        </el-form-item>
                                    </el-row>
                                    <el-row>
                                        <el-form-item label="变更原因" prop="changeReason">
                                            <span>{{ formData.changeReason }}</span>
                                        </el-form-item>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="本位币" prop="baseCurName">
                                                <!-- 传id和名称 -->
                                                <span>{{ formData.baseCurName }}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col
                                            :span="12"
                                            v-if="formData.baseCurName !== formData.currency"
                                        >
                                            <el-form-item label="人民币汇率" prop="rmbRate">
                                                <span>{{ formData.rmbRate }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12" v-if="formData.releaseState === 1">
                                            <el-form-item label="发布时间：">
                                                <!-- 传id和名称 -->
                                                <span>{{ formData.relaseTime }}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </div>
                        </div>

                        <div id="detailCon" class="con">
                            <div class="tabs-title" id="detail">包件信息</div>
                            <div>
                                <ComDetailsOfProposedIndex
                                    ref="ComDetailsOfProposedIndex"
                                    :tenderData="formData"
                                    v-model="detailsData"
                                    @onChangeTab="onChangeTab"
                                    :tenderListData="tenderListData"
                                    :auditState="auditState"
                                />
                            </div>
                        </div>

                        <div id="tenderListCon" class="con">
                            <div class="tabs-title" id="tenderList">招标清单</div>
                            <!-- :isAdd="auditState.canModify"
                                :isEdit="auditState.canModify" -->
                            <ComtenderListIndex
                                ref="ComtenderListIndex"
                                :auditState="auditState"
                                :state="formData.state"
                                :detailsData="detailsData"
                                v-model="tenderListData"
                            />
                        </div>

                        <div id="clarification" class="con" v-if="formData.count !== 0">
                            <div class="tabs-title" id="clause">
                                补遗澄清
                                <!-- <el-button @click="saveClar">测试保存</el-button> -->
                            </div>
                            <ComQuillEditor ref="ComQuillEditor" v-model="clauseParams.content" />
                        </div>

                        <div id="clauseCon" class="con">
                            <div class="tabs-title" id="clause">条款需求未定</div>
                            <!-- <div class="tabs-title" id="clause">通用合同条款</div>
                            <div class="e-table" style="min-height: auto">
                                <el-table
                                    :data="tableData"
                                    border
                                    style="width: 100%"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    :cell-class-name="cellClsNm"
                                >
                                    <el-table-column show-overflow-tooltip prop="a1" label="序号">
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="a"
                                        label="所属单位"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="b"
                                        label="通用合同条款编号"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="c"
                                        label="合同条款名称"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="d"
                                        label="条款明细查阅"
                                    >
                                    </el-table-column>
                                </el-table>
                                <ComPagination />
                            </div>

                            <div class="tabs-title" style="margin-top: 20px">项目专用合同条款</div>
                            <div class="e-table" style="min-height: auto; margin-bottom: 20px">
                                <div class="top">
                                    <div class="left">
                                        <div>
                                            <el-button size="small" class="btn-greenYellow"
                                                >新增</el-button
                                            >
                                            <el-button size="small" class="btn-greenYellow"
                                                >删除</el-button
                                            >
                                        </div>
                                    </div>
                                </div>
                                <el-table
                                    :data="tableData"
                                    border
                                    style="width: 100%"
                                    @cell-mouse-enter="cellMouseEnter"
                                    @cell-mouse-leave="cellMouseLeave"
                                    :cell-class-name="cellClsNm"
                                >
                                    <div class="top">
                                        <div class="left">
                                            <el-button size="mini">新增</el-button>
                                            <el-button size="mini">删除</el-button>
                                        </div>
                                    </div>
                                    <el-table-column show-overflow-tooltip prop="a1" label="序号">
                                    </el-table-column>
                                    <el-table-column show-overflow-tooltip prop="a" label="条目号">
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="b"
                                        label="原条款内容"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        show-overflow-tooltip
                                        prop="c"
                                        label="专用合同条款内容"
                                    >
                                    </el-table-column>
                                </el-table>
                                <ComPagination />
                            </div> -->
                        </div>

                        <div id="attachCon" class="con">
                            <div class="tabs-title" id="attach">附件信息</div>
                            <ComAttachIndex
                                bucketName="tender"
                                :relationId="billId"
                                :isView="
                                    (auditState.canAudit === false &&
                                        auditState.canModify === false) ||
                                    Object.keys(auditState).length === 0
                                "
                                ref="ComAttachIndex"
                                :key="2"
                            />
                        </div>

                        <div id="auditHistoryCon" class="con">
                            <div class="tabs-title" id="auditHistory">审核历史</div>
                            <ComExaHistory billType="60291" ref="ComExaHistory" />
                        </div>
                    </div>
                </el-tabs>
            </div>
            <div class="buttons">
                <ComBidButtons
                    :formData="formData"
                    api="equipmentLeasing"
                    ref="ComBidButtons"
                    :releaseState="false"
                    releaseType="2"
                    :onlyRelease="true"
                    @getData="getData"
                />
                <el-button
                    type="primary"
                    class="btn-blue"
                    size="small"
                    v-if="
                        formData.state === 2 && formData.releaseState !== 1 && formData.count !== 0
                    "
                    @click="release"
                    >发布</el-button
                >
                <ComExaButtons
                    :auditState="auditState"
                    @exas="exas"
                    :routeTo="
                        () => {
                            this.$router.push({
                                path: './equipHireBiddingApplicationEdit',
                                query: {
                                    billid: this.tenderId,
                                    seat: 'recodes'
                                }
                            })
                        }
                    "
                    :founderId="formData.founderId"
                    :state="formData.state"
                    v-if="formData.count !== 0"
                    :isPrint="false"
                />
                <el-button @click="handleClose" size="small">关闭</el-button>
            </div>
            <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
        </div>
        <!-- dialog -->
        <ComNoticeDialog
            ref="ComNoticeDialog"
            :dialogVisible.sync="dialogVisible"
            :tenderClass="parseInt(formData.tenderClass)"
            :tenderForm="String(formData.tenderForm)"
            v-if="Object.keys(formData).length !== 0"
            :content="formData.tenderNotice"
            @save="noticeSave"
            :canEdit="auditState.canModify"
        />
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
// import ComTreeTable from '@/templates/table/treeTable.vue'
// import ComTreeFile from '@/templates/table/treeFile.vue'
// import ComPagination from '@/components/pagination/pagination.vue'
import ComNoticeDialog from '@/components/common/noticeDialog.vue'
import ComDetailsOfProposedIndex from '@/pages/bidding/equipHireBidding/detailsOfProposed/addenDetailsOfProposedIndex'
import ComtenderListIndex from '@/pages/bidding/equipHireBidding/tenderList/addenTenderListIndex'
import ComQuillEditor from '@/components/quillEditor.vue'
import ComAttachIndex from '@/components/common/attachIndex'
import ComExaButtons from '@/components/common/exaButtons'
import ComExaHistory from '@/components/common/exaHistory.vue'
import ComShowBiddingButton from '@/pages/bidding/common/showBiddingButton.vue'
import ComInputSelectUnit from '@/pages/bidding/common/inputSelectUnit.vue'
// import tenderRequest from '@/api/tender/tender.js'
import auditRequest from '@/api/tender/audit.js'
import equipmentLeasingRequest from '@/api/tender/equipmentLeasing.js'
import commonRequest from '@/api/tender/common.js'
import ComNullify from '@/pages/bidding/common/nullify.vue'
import ComBidButtons from '@/components/bidding/bidButtons'
import { openAppClient } from '@/utils/common'
import { mapState, mapMutations } from 'vuex'

export default {
    data () {
        const not0RmbRate = (rule, value, callback) => {
            if (typeof value === 'number' && value === 0) {
                return callback(new Error('人民币汇率不能为0'))
            } else {
                callback()
            }
        }
        const greaterZero = (rule, value, callback) => {
            if (typeof value === 'number' && value < 0) {
                return callback(new Error('不能为负数'))
            } else {
                callback()
            }
        }
        return {
            tabsName: 'baseInfo',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableData: [],
            value: '',
            textarea: '',
            formData: {},
            test: '',
            selectData: [],
            selectTableColumnAttr: [
                {
                    label: '机构Id',
                    prop: 'orgId'
                },
                {
                    label: '机构名称',
                    prop: 'orgName'
                }
            ],
            selectTableColumnWidth: {
                leftWidth: '150',
                rightWidth: '100'
            },
            selectDataPagination: {},
            dialogVisible: false,
            rules: {
                purchaseDemandStatement: {
                    required: true,
                    message: '请输入采购需求陈述',
                    trigger: 'blur'
                },
                changeReason: [
                    {
                        required: true,
                        message: '请输入变更原因',
                        trigger: 'blur'
                    },
                    {
                        min: 1,
                        max: 500,
                        message: '最多允许输入500个汉字',
                        trigger: 'blur'
                    }
                ],
                tenderNotice: {
                    required: true,
                    message: '请输入公告',
                    trigger: 'change'
                },
                billNo: {
                    required: true,
                    message: '请输入招标编号',
                    trigger: 'blur'
                },
                tenderName: {
                    required: true,
                    message: '请输入拟招标项目名称',
                    trigger: 'blur'
                },
                tenderForm: {
                    required: true,
                    message: '请选择招标方式',
                    trigger: 'change'
                },
                tenderType: {
                    required: true,
                    message: '请选择招标类型',
                    trigger: 'change'
                },
                projectName: {
                    required: true,
                    message: '请输入项目名称',
                    trigger: 'blur'
                },
                tenderBail: [
                    {
                        required: true,
                        message: '请输入投标保证金（元）',
                        trigger: 'blur'
                    },
                    // { type: 'number', message: '保证金必须为数字值' },
                    { validator: greaterZero, trigger: 'blur' }
                ],
                currencyId: {
                    required: true,
                    message: '请选择币种',
                    trigger: 'change'
                },
                tenderAmount: {
                    required: true,
                    message: '请输入拟招标金额（元）',
                    trigger: 'blur'
                },
                taxAmount: {
                    required: true,
                    message: '请输入税额',
                    trigger: 'blur'
                },
                applyTime: {
                    required: true,
                    message: '请选择申请日期',
                    trigger: 'change'
                },
                tenderState: {
                    required: true,
                    message: '请输入招标状态',
                    trigger: 'blur'
                },
                state: {
                    required: true,
                    message: '请输入申请状态',
                    trigger: 'blur'
                },
                applyOrgName: {
                    required: true,
                    message: '请选择申请单位',
                    trigger: 'change'
                },
                projectOverview: {
                    required: true,
                    message: '请输入招标项目工程概况',
                    trigger: 'blur'
                },
                remarks: [
                    // { required: true, message: '请输入备注', trigger: 'blur' },
                    {
                        max: 500,
                        message: '最多允许输500个汉字',
                        trigger: 'blur'
                    }
                ],
                orgName: {
                    required: true,
                    message: '请输入录入机构',
                    trigger: 'blur'
                },
                tenderUser: {
                    required: true,
                    message: '请选择招标单位',
                    trigger: 'change'
                },
                baseCurName: {
                    required: true,
                    message: '没有设置本位币，请联系集团信息化管理员设置！',
                    trigger: 'blur'
                },
                rmbRate: [
                    {
                        required: true,
                        message: '请选择币种',
                        trigger: 'change'
                    },
                    { validator: not0RmbRate, trigger: 'change' }
                ],
                centralizedPurchasingState: {
                    required: true,
                    message: '请选择集中租赁',
                    trigger: 'change'
                },
                tenderFee: [
                    {
                        required: true,
                        message: '请输入购买标书费用',
                        trigger: 'blur'
                    },
                    { type: 'number', message: '购买标书费用必须为数字值' },
                    { validator: greaterZero, trigger: 'blur' }
                ],
                tenderEndTime: {
                    required: true,
                    message: '请选择投标截止时间',
                    trigger: 'change'
                },
                pushPurchasePlatformState: {
                    required: true,
                    message: '请选择发布到招采平台',
                    trigger: 'change'
                },
                leaseType: {
                    required: true,
                    message: '请选择租赁类型',
                    trigger: 'change'
                }
            },
            detailsData: [], // 包件信息
            tenderListData: [], // 清单数据
            auditState: {},
            auditParams: {
                billId: this.$route.query.billid,
                billType: 60291,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
            nullifyParams: {
                billId: this.$route.query.billid,
                billType: 60291,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: ''
            },
            clauseParams: {
                billId: '',
                content: '',
                recordId: ''
            },
            MouseEnterId: 0
        }
    },
    watch: {
        detailsData: {
            handler (val) {
                // 计算拟采购金额
                this.formData.tenderAmount = val.reduce((prev, cur) => (prev += cur.priceLimit), 0)
                // 计算税额
                this.formData.taxAmount = parseFloat(
                    val
                        .reduce((prev, cur) => (prev += cur.taxAmount + cur.freightTax), 0)
                        .toFixed(2)
                )
            },
            deep: true
        },
        'formData.tenderForm': {
            handler (val) {
                if (val === '1') {
                    this.formData.pushPurchasePlatformState = 1
                }
            },
            immediate: true
        }
    },
    computed: {
        ...mapState({
            options: state => state.biddingApplication.dictionaries
        }),
        tenderId () {
            return this.$route.query.tenderId
        },
        billId () {
            return this.$route.query.billId || this.$route.query.billid
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        }
    },
    components: {
        // ComTreeTable,
        // ComTreeFile,
        // ComPagination,
        ComNoticeDialog,
        ComDetailsOfProposedIndex,
        ComtenderListIndex,
        ComQuillEditor,
        ComAttachIndex,
        ComExaButtons,
        ComExaHistory,
        ComShowBiddingButton,
        ComInputSelectUnit,
        ComNullify,
        ComBidButtons
    },
    created () {
        // 编辑不用查询招标信息，直接编辑当前billId信息
        this.getData()
        // 获取澄清信息
        this.clarificationFindById()
        // 获取审核相关按钮接口
        this.getCurrentUnitInfo()
    },
    mounted () {
        // 保存所有tabName
        const arr = [
            'baseInfo',
            'detail',
            'tenderList',
            'clarification',
            'clause',
            'attach',
            'auditHistory'
        ]
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight(arr)
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const itemTop = document.getElementById(item)?.offsetTop
                    return itemTop
                })
            }
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item)?.offsetTop
                return itemTop
            })
        })
    },
    beforeDestroy () {
        this.$notify.closeAll()
    },
    methods: {
        ...mapMutations(['setAuditParams', 'setSelectedInfo']),
        release () {
            var params = { billId: this.billId, type: 2 }
            equipmentLeasingRequest.release(params).then(() => {
                this.clientPop('suc', '发布成功')
            })
        },
        inputblur (row, val) {
            row[val] = isNaN(parseFloat(row[val])) ? 0 : parseFloat(row[val])
        },
        clarificationFindById () {
            this.clauseParams.billId = this.billId
            equipmentLeasingRequest.clarificationFindById({ id: this.billId }).then(res => {
                if (res.content !== null) {
                    this.clauseParams = res
                }
            })
        },
        getAuditHistory () {
            auditRequest.getAuditHistory(this.auditParams).then(res => {
                this.$refs.ComExaHistory.tableData = res
                this.$refs.ComExaHistory.pagination.total = res.length
            })
        },
        saveAllData (notice = true) {
            return new Promise((resolve, reject) => {
                // 基础信息验证
                this.$refs.ruleForm.validate(async valid => {
                    if (!valid) {
                        this.onChangeTab({ name: 'baseInfo' })
                        reject()
                        return false
                    }
                })
                // 澄清验证
                if (this.clauseParams.content === '') {
                    this.onChangeTab({ name: 'clarification' })
                    this.clientPop('err', '请填写澄清信息')
                    reject()
                    return false
                }
                // 基础信息
                const promise1 = this.submit()
                // 包件
                const promise2 = (() => {
                    if (this.$refs?.ComDetailsOfProposedIndex) {
                        return this.$refs.ComDetailsOfProposedIndex.save()
                    }
                })()
                // 清单
                const promise3 = (() => {
                    if (this.$refs?.ComtenderListIndex) {
                        return this.$refs.ComtenderListIndex.save()
                    }
                })()
                // 招标澄清
                const promise4 = (() => {
                    this.saveClar()
                })()
                Promise.all([promise1, promise2, promise3, promise4])
                    .then(() => {
                        resolve()
                        if (!notice) return
                        this.clientPop('suc', '保存成功')
                    })
                    .catch(err => {
                        console.log('err', err)
                        reject()
                    })
            })
        },
        // 审核相关操作
        async exas (arg, routeTo) {
            if (arg === 'audit') {
                // 包件验证
                if (!this.$refs.ComDetailsOfProposedIndex.detailRule()) return
                // 清单验证
                if (!this.$refs.ComtenderListIndex.tenderListRule()) return
                this.saveAllData(false)
                this.setAuditParams(this.auditParams)
                // 客户端弹窗弹出本地页面
                openAppClient('/exaDialog', '填写审核意见', () => {
                    const auditParams = JSON.parse(localStorage.vuex).auditParams
                    auditRequest.audit(auditParams).then(() => {
                        if (auditParams.isPass) {
                            this.clientPop('suc', '审核成功', routeTo)
                        } else {
                            this.clientPop('suc', '返回修改成功', routeTo)
                        }
                        this.getCurrentUnitInfo()
                        this.getData()
                        this.$refs.ComExaHistory.getAuditHistory()
                    })
                }, null, null, null, 'small')
            } else if (arg === 'undoAudit') {
                this.clientPop('info', '确定要撤回上一步审核操作吗？', () => {
                    auditRequest.undoAudit(this.auditParams).then(() => {
                        this.clientPop('suc', '撤回成功', routeTo)
                        this.getCurrentUnitInfo()
                        this.getData()
                        this.$refs.ComExaHistory.getAuditHistory()
                    })
                })
            } else if (arg === 'submitCommit') {
                // 包件验证
                if (!this.$refs.ComDetailsOfProposedIndex.detailRule()) return
                // 清单验证
                if (!this.$refs.ComtenderListIndex.tenderListRule()) return
                // 保存所有信息
                const promise1 = await this.saveAllData(false)
                // 审核
                const promise2 = auditRequest.commit(this.auditParams)
                Promise.all([promise1, promise2]).then(() => {
                    this.clientPop('suc', '保存并提交成功', routeTo)
                    this.getCurrentUnitInfo()
                    this.getData()
                    this.$refs.ComExaHistory.getAuditHistory()
                })
                //     } else {
                //         return false
                //     }
                // })
            } else if (arg === 'submit') {
                this.saveAllData()
            } else if (arg === 'nullify') {
                this.setAuditParams(this.nullifyParams)
                // 客户端弹窗弹出本地页面
                openAppClient('/nullifyDialog', '单据作废原因', () => {
                    const auditParams = JSON.parse(localStorage.vuex).auditParams
                    commonRequest.nullify(auditParams).then(() => {
                        this.clientPop('suc', '作废成功', routeTo)
                        this.getCurrentUnitInfo()
                        this.getData()
                        this.$refs.ComExaHistory.getAuditHistory()
                    })
                }, null, null, null, 'small')
            } else if (arg === 'deleteData') {
                this.clientPop('info', '确定要删除吗？数据删除后不可恢复，请谨慎操作！', () => {
                    equipmentLeasingRequest.changeDelete({ id: this.billId }).then(() => {
                        const callBack = () => {
                            this.$router.push({
                                path: './equipHireBiddingApplicationEdit',
                                query: {
                                    billid: this.tenderId,
                                    seat: 'recodes'
                                }
                            })
                        }
                        this.clientPop('suc', '删除成功', callBack)
                    })
                })
            }
        },
        getCurrentUnitInfo () {
            auditRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                this.auditState = res
                console.log('auditState', this.auditState)
            })
        },
        saveClar () {
            equipmentLeasingRequest.clarificationCreate(this.clauseParams).then(() => {
                this.clarificationFindById()
            })
        },
        noticeSave (content) {
            this.formData.tenderNotice = content
        },
        handleNotice () {
            this.dialogVisible = true
        },
        deleteData () {
            this.clientPop('info', '确定要删除吗？数据删除后不可恢复，请谨慎操作！', this.delData)
        },
        onChangeTab (e) {
            const height = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight (arr) {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById(arr[length - 1] + 'Con')) {
                    const lastConHeight = document.getElementById(
                        arr[length - 1] + 'Con'
                    )?.offsetHeight
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        openNewPage (name) {
            this.$notify.closeAll()
            if (name === 'OrgSelectData') {
                const params = JSON.stringify({
                    // 正式环境应该不用转换
                    title: '申请机构',
                    url: '/hr/org/getChildrenOrg',
                    method: 'get',
                    params: { orgId: this.$store.state.userInfo.orgInfo.orgId },
                    tableColumnAttr: this.selectTableColumnAttr,
                    tableColumnWidth: this.selectTableColumnWidth,
                    ifPagination: 0
                })
                this.$notify({
                    title: '申请机构',
                    dangerouslyUseHTMLString: true,
                    message: `正式环境：客户端打开新页面<br>
                测试环境：手动打开新页面<br>
                <textarea cols="35" rows="10">http://localhost:8080/selectData?params=${params}</textarea>
                <br><br>
                回调参数：<br>
                <textarea cols="35" rows="3" id="callBackData"></textarea><br>
                <button id="getPopData">执行回调方法</button>
                `,
                    duration: 0
                })
                document.querySelector('#getPopData').addEventListener('click', this.getPopData)
            }
        },
        getPopData () {
            const callBackData = JSON.parse(document.querySelector('#callBackData').value)
            this.formData.applyOrgId = callBackData.orgId
            this.formData.applyOrgName = callBackData.orgName
        },
        selectChange (kvId, label) {
            if (label === '采购方式') {
                this.options.tenderForm.forEach(item => {
                    if (kvId === item.value) {
                        this.formData.tenderFormName = item.label
                    }
                })
            } else if (label === '币种') {
                this.options.currency.forEach(item => {
                    if (item.kvValue === kvId) {
                        this.formData.currency = item.kvKey
                    }
                })
            } else if (label === '目标预算') {
                ;('等待接口')
            }
        },
        noFocus () {
            this.$refs1.noFocus.blur()
            this.$refs2.noFocus.blur()
        },
        showBidding () {
            if (!this.tenderId) return // 前期需求可切换，现在不需要
            this.$notify.closeAll()
            this.$notify({
                title: '查看招标详情',
                dangerouslyUseHTMLString: true,
                message: `正式环境：客户端打开新页面<br>
                测试环境：手动打开新页面<br>
                <textarea cols="35" rows="10">http://localhost:8080/biddingApplicationShow?tenderId=${this.tenderId}</textarea>
                `,
                duration: 0
            })
            // this.$router.push({
            //     path: './biddingApplicationShow',
            //     query: { tenderId: this.tenderId }
            // })
        },
        delData () {
            equipmentLeasingRequest.changeDelete({ id: this.billId }).then(() => {
                const callBack = () => {
                    this.$router.push({
                        path: './equipHireBiddingApplicationEdit',
                        query: { billid: this.tenderId, seat: 'recodes' }
                    })
                }
                this.clientPop('suc', '删除成功', callBack)
            })
        },
        getData () {
            equipmentLeasingRequest.changeFindById({ id: this.billId }).then(res => {
                this.formData = res
            })
        },
        submit () {
            console.log('submit')
            equipmentLeasingRequest.changeUpdate(this.formData)
        },
        handleClose () {
            this.$router.push({
                path: './equipHireBiddingApplicationEdit',
                query: { billid: this.tenderId, seat: 'recodes' }
            })
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        }
        // cellMouseEnter (row) {
        //     this.MouseEnterId = row.id
        // },
        // cellMouseLeave () {
        //     this.MouseEnterId = 0
        // }
    }
}
</script>

<style lang="scss" scoped>
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
  .left {
    padding: 20px;
    padding-top: 0px;
  }
} */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
